package info.zhoutian.blog.handle;

import info.zhoutian.blog.domain.Result;
import info.zhoutian.blog.exception.GirlException;
import info.zhoutian.blog.utils.ResultUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

/**
 * Created by Administrator on 2018/8/24.
 */
@ControllerAdvice
public class ExceptionHandle {

    private final static Logger logger = LoggerFactory.getLogger(ExceptionHandle.class);

    @ExceptionHandler(value = Exception.class)
    @ResponseBody
    public Result handle(Exception e){
        if(e instanceof GirlException){
            GirlException e1 = (GirlException) e;
            return ResultUtil.failere(e1.getCode(),e1.getMessage());
        }else{
            logger.error("系统异常：{}",e);

            return ResultUtil.failere(-1,"未知错误");
        }


    }
}
